﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data;

namespace BLL
{
   public class ClsThachHocBus
    {
      public ClsThachHocInfo Info = new ClsThachHocInfo();
      public DataTable TimKiemGK()
      {
          ClsDataAccess oConnection = new ClsDataAccess();
          string strSql = @"SELECT TTCHUNG.TenGK,ThachHoc.MaLop,ThachHoc.ChieuSau,ThachHoc.DoDayThucLop,ThachHoc.TyLeMau,ThachHoc.ThachHoc1,ThachHoc.ThachHoc2,ThachHoc.ThachHoc3,ThachHoc.ThachHoc4,ThachHoc.MoTa
                              FROM TTCHUNG, ThachHoc
                              WHERE TTCHUNG.MaGK= ThachHoc.MaGK 
                              AND TTCHUNG.MaGK like'%" + Info.MaGK +
                             "%'AND TTCHUNG.Tinh LIKE '%" + Info.MaTinh + "%'";

          if (oConnection.ExecuteSelect(strSql))
          {
              oConnection.ODataTable.Columns.Add("STT");
              int i = 0;
              foreach (DataRow oDRow in oConnection.ODataTable.Rows)
              {
                  oDRow["STT"] = (i + 1);
                  i++;
              }
              return oConnection.ODataTable;
          }
          else
          {
              return null;
          }
      } 

        public DataTable SelectAll()
        {
            ClsDataAccess oConnection = new ClsDataAccess();
            string strSql = @"SELECT TTCHUNG.TenGK,ThachHoc.MaLop,ThachHoc.ChieuSau,ThachHoc.DoDayThucLop,ThachHoc.TyLeMau,ThachHoc.ThachHoc1,ThachHoc.ThachHoc2,ThachHoc.ThachHoc3,ThachHoc.ThachHoc4,ThachHoc.MoTa
                              FROM TTCHUNG, ThachHoc
                              WHERE TTCHUNG.MaGK= ThachHoc.MaGK
                              AND TTCHUNG.Tinh LIKE '%" + Info.MaTinh + "%'";;
            //string strSql = @"SELECT * From ThachHoc";
            if (oConnection.ExecuteSelect(strSql))
            {
                oConnection.ODataTable.Columns.Add("STT");
                int i = 0;
                foreach (DataRow oDRow in oConnection.ODataTable.Rows)
                {
                    oDRow["STT"] = (i + 1);
                    i++;
                }
                return oConnection.ODataTable;
            }
            else return null;
        }

        public DataTable LoadGK()
        {
            ClsDataAccess oConnection = new ClsDataAccess();
            string strSql = @"SELECT MaGK,TenGK FROM TTCHUNG WHERE AND TTCHUNG.Tinh LIKE '%" + Info.MaTinh + "%'";
            if (oConnection.ExecuteSelect(strSql))
            {
                return oConnection.ODataTable;
            }
            else
            {
                return null;
            }
        }
        public bool Them()
        {
           string strSql = "EXECUTE InsertThachLoc'" +Info.MaGK +"','"+Info.MaLop + "','" +Info.ChieuSau + "','"+Info.DoDayThucLop + "','"+Info.TyLeMau + "',N'"+ Info.ThachHoc1 + "',N'"+ Info.ThachHoc2 +"',N'"+Info.ThachHoc3 + "',N'" +Info.ThachHoc4 +"',N'"+Info.MoTa+ "'";
            
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));
        }

        public bool Sua()
        {
            string strSql = "EXECUTE UpdateThachLoc'" + Info.MaGK + "','" + Info.MaLop + "','" + Info.ChieuSau + "','" + Info.DoDayThucLop + "','" + Info.TyLeMau + "',N'" + Info.ThachHoc1 + "',N'" + Info.ThachHoc2 + "',N'" + Info.ThachHoc3 + "',N'" + Info.ThachHoc4 + "',N'" + Info.MoTa + "'";
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));
        }
        public bool xoa()
        {
            //string strSql = @"DELETE FROM ThachHoc WHERE MaGK='" + Info.MaGK + "'AND MaLop= '"+Info.MaLop+"'" ;
            string strSql = "EXECUTE DeleteThachLoc'" + Info.MaGK + "',N'" + Info.MaLop + "'";
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));
        }
    }
}
